package modular.demo1;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowCountMapper extends Mapper<LongWritable, Text, Text, FlowBean> {


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String line = value.toString();

        String[] fields = line.split("\\$");

        String phone = fields[0];
        int upFlow = Integer.parseInt(fields[1]);
        int downFlow = Integer.parseInt(fields[2]);

        context.write(new Text(phone), new FlowBean(upFlow, downFlow, upFlow + downFlow, phone));


    }
}
